﻿CREATE FUNCTION [acms].[GetParentSequence]
(
	@ParentId int
)
RETURNS VARCHAR(50)
AS
BEGIN
	declare @NewParentId int
	declare @ParentSequence varchar(2000)
	declare @Sequence int
	
	select @NewParentId = ParentId, @Sequence = Sequence From PageVersions Where PostId = @ParentId
	
	if @NewParentId is not null
		set @ParentSequence = [acms].[GetParentSequence](@NewParentId)
	else
		set @ParentSequence = ''
	
	return @ParentSequence + cast(@Sequence as varchar(3))

END